import CryptoJS from 'crypto-js'

const APPID='5f711f96'
const APIKey='046774733dfbfb0e4e3b9f4317101583'
const host='api.xf-yun.com'

const APISecret="apisecretXXXXXXXXXXXXXXXXXXXXXXX"
const date="Wed, 11 Aug 2021 06:55:18 GMT"

//拼接生成字符串tmp
const tmp=`host: ${host}\ndate: ${date}\nPOST /v1/private/sf8e6aca1 HTTP/1.1` //注意空格必须保留

//tmp加密获取哈希函数 SHA-256 和一个密钥来生成的消息认证码
const hash=CryptoJS.HmacSHA256(tmp,'apisecretXXXXXXXXXXXXXXXXXXXXXXX')
console.log(hash)

//tmp_sha进行base64编码生成signature
const signature=CryptoJS.enc.Base64.stringify(hash)
console.log('signature',signature) // /mg2h9BCkespilZ94HUBaQVPq2v7PxYF90teTBlaxd8=

